<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>登录页面</title>

    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">

    <style type="text/css">
        body {
            background-color: #2e2e2e;
            color: white;
        }

        .row h1 {
            color: #ffc600;
        }

        .control-label {
            color: black;
        }

        #heading {
            background-color: black;
            color: #ffc600;
        }

        .panel-default {
            border-color: #ffc600;
        }

        input[type='checkbox'] {
            position: relative;
            top: 7px;
            left: -10px;
        }
    </style>
</head>
<body>
<!--登录页标题-->
<header>
    <div class="container">
        <div class="row">
            <div class="col-md-offset-2 col-md-8">
                <h1>
                    <small>欢迎使用</small> <b>鸟哥笔记</b>后台管理系统
                </h1>
            </div>
        </div>
    </div>
</header>
<div class="container">
    <div class="row">
        <div class="col-md-offset-2 col-md-8">
            <!--登录面板-->
            <div class="panel panel-default">
                <!--面板标题-->
                <div class="panel-heading" id="heading">
                    <h2 class="panel-title">登录</h2>
                </div>
                <!--面板主体-->
                <div class="panel-body">
                    <!--登录表单-->
                    <form id="myform" class="form-horizontal" role="form"
                          action="loginaction" method="post">
                        <!--用户名-->
                        <div class="form-group">
                            <label for="name" class="col-md-2 control-label">用户名</label>
                            <div class="col-md-8">
                                <input type="text" v-model="managername"
                                       class="form-control" id="name" name="managername"
                                       placeholder="请输入用户名">
                            </div>
                        </div>
                        <!--密码-->
                        <div class="form-group">
                            <label for="pwd" class="col-md-2 control-label">密码</label>
                            <div class="col-md-8">
                                <input type="password" v-model="password"
                                       class="form-control" id="pwd" name="password"
                                       placeholder="请输入密码">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="pwd" class="col-md-3 control-label">记住用户名和密码</label>
                            <div class="col-md-9">
                                <input type="checkbox" name="rem">
                            </div>
                        </div>
                        <!--登录按钮-->
                        <div class="form-group">
                            <div class="col-md-offset-2 col-md-10">
                                <button type="button" class="btn btn-default sublogin" @click="login()">登录</button>
                                <span></span>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
<!--网页页脚-->
<footer>
    <div class="container">
        <div class="text-center">
            Powered by 鸟哥笔记 X3.2 © 2010-2021
            <a target="_blank" href="/index.html">鸟哥笔记</a>
            沪ICP备14028330号-7
        </div>
    </div>
</footer>
</body>

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<!--引入vue-->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<!--引入axios框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script>
let v=new Vue({
    el:"form",
    data:{
        username:"",password:""
    },
    methods:{
        login:function () {
            /*得到form表单中的数据*/
            let data=new FormData(document.querySelector("form"));
            axios.post("/login",data).then(function (response) {
                if(response.data==1){
                    alert("登录成功！")
                    location.href="/admin.html";
                }else if(response.data==0){
                    alert("管理员不存在！")
                }else {
                    alert("密码错误！")
                }
            });
        }
    }
})

//    得到Cookie里面保存的用户名和密码  并显示到页面
    let cookie=document.cookie;
//password=123456;username=admin
    let cookieArr=cookie.split(";");
    //forof 相当于Java中的foreach
    for (let c of cookie){
        let arr=c.split("=");
        //得到=前边的内容  trim是未来去掉可能存在的空格
        let key=arr[0].trim();
        let value=arr[1];/*  = 后边的内容   */
        /*判断用户名或密码把值给到Vue中的变量，由于页面内容和此便来给你进行了双向绑定
        * 页面会自动发生改变*/
        if(key=="username"){
            v.username=value;
        }
        if (key=="password"){
            v.password=value;
        }

    }
</script>
</html>

















